/*
 * NewGPPlayer.java
 *
 * Created on May 13, 2006, 9:29 PM
 */

package poppitplayer.gui;

import ec.simple.SimpleEvolutionState;
import ec.Evolve;
import ec.Individual;
import java.io.*;
import javax.swing.*;

/**
 *
 * @author  datacomm
 */
public class NewGPPlayer extends javax.swing.JFrame {
    
    /** Creates new form NewGPPlayer */
    public NewGPPlayer() {
        this.startForm = new Start();
        initComponents();
    }
    
    /** Creates new form NewGPPlayer */
    public NewGPPlayer(Start aForm) {
        this.startForm = aForm;
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jComboBoxFunctionsType = new javax.swing.JComboBox();
        jTextFieldGens = new javax.swing.JTextField();
        jTextFieldDepth = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jCheckBoxElitism = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldSubPopSize = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("New GP Player Options");
        jLabel1.setLabelFor(jComboBoxFunctionsType);
        jLabel1.setText("Functions Type");

        jComboBoxFunctionsType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Domain Specific", "Domain Specific + ADF", "Non-Domain Specific" }));

        jTextFieldGens.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldGens.setText("50");

        jTextFieldDepth.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldDepth.setText("12");

        jLabel2.setLabelFor(jTextFieldDepth);
        jLabel2.setText("Generations:");

        jLabel3.setLabelFor(jTextFieldGens);
        jLabel3.setText("Tree Depth:");

        jCheckBoxElitism.setText("Use Elitism:    ");
        jCheckBoxElitism.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxElitism.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jCheckBoxElitism.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jButton1.setText("OK");

        jLabel4.setText("Subpopulation size:");

        jTextFieldSubPopSize.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldSubPopSize.setText("1024");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(63, 63, 63)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel3)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel4)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel2))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jTextFieldGens, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jTextFieldDepth, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jTextFieldSubPopSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(layout.createSequentialGroup()
                        .add(92, 92, 92)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jCheckBoxElitism)
                            .add(jButton1)))
                    .add(layout.createSequentialGroup()
                        .add(77, 77, 77)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel1)
                            .add(jComboBoxFunctionsType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(98, Short.MAX_VALUE))
        );

        layout.linkSize(new java.awt.Component[] {jTextFieldDepth, jTextFieldGens, jTextFieldSubPopSize}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(27, 27, 27)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jComboBoxFunctionsType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(jTextFieldGens, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jTextFieldSubPopSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(jTextFieldDepth, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jCheckBoxElitism)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 35, Short.MAX_VALUE)
                .add(jButton1)
                .add(23, 23, 23))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    public void loadPlayer(){
        JFileChooser fc = new JFileChooser();
        int returnVal = fc.showOpenDialog(this);
        
        if (returnVal == JFileChooser.APPROVE_OPTION){
            File file = fc.getSelectedFile();
            //System.out.println("Loading file " + file.getAbsolutePath());
            try{
                FileInputStream f_in = new FileInputStream(file.getAbsolutePath());
                ObjectInputStream obj_in = new ObjectInputStream(f_in);
                this.loadedPlayer = (Individual)obj_in.readObject();
            }catch(IOException ex){
                ex.printStackTrace();
            }catch(ClassNotFoundException ex){
                ex.printStackTrace();
            }
            this.gpGenerations = 1;
            this.subPopSize = 1;
            this.isLoadedPlayer = true;
            this.setVisible(false);
            startForm.gameType.setVisible(true);
        }else{
            System.out.println("User cancelled load.");
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewGPPlayer().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBoxElitism;
    private javax.swing.JComboBox jComboBoxFunctionsType;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField jTextFieldDepth;
    private javax.swing.JTextField jTextFieldGens;
    private javax.swing.JTextField jTextFieldSubPopSize;
    // End of variables declaration//GEN-END:variables
    private Start startForm;
    public int gpGenerations = 50;
    public int subPopSize = 1024;
    public int depth = 12;
    public boolean useElitism = false;
    public String functionsType = "Domain Specific";
    public SimpleEvolutionState state;
    public boolean isLoadedPlayer = false;
    public Individual loadedPlayer;
}
